package org.xussen.dic;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexKeywordTest {

	private static String charEncoding = "UTF-8";
	private static String path = "data/library1.dic";
	
	public static void main(String[] args) throws IOException {
		String content = "是嘛呀hi发我个可额哈地灯而人可i场疯" +
				"看偶哈i发我个可额哈地灯而人可i场疯看偶哈i发我个可额哈地灯" +
				"而人可i场疯看偶哈i发我个可额哈地灯而人可i场疯看偶哈i发我" +
				"个可额哈地灯而人可i场疯看偶哈i发我个可额哈地灯而人可i场疯看" +
				"偶哈sd卡妇额女节的你共产党";
		BufferedReader reader = IOUtil.getReader(path, charEncoding);
		String con = init(reader);
		long startPattern = System.currentTimeMillis();
		Pattern pattern = Pattern.compile(con);
		System.out.println("初始化时间:"+(System.currentTimeMillis()-startPattern));
		boolean m = false;
		long start = System.currentTimeMillis();
		for (int i = 0; i < 3; i++) {
			Matcher matcher = pattern.matcher(content);
			m = matcher.find();
		}
		System.out.println(System.currentTimeMillis()-start);
		System.out.println(m);
	}

	private static String init(BufferedReader reader) throws IOException {
		String temp = null;
		temp = reader.readLine();
		if(temp == null)return "";
		StringBuilder last = new StringBuilder(temp);
		while ((temp = reader.readLine()) != null) {
			last.append("|").append(temp);
		}
		return last.toString();
	}

}
